﻿#region Using directives

using System;
using System.ComponentModel;
using System.Collections;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

#endregion

namespace SPL.Entities
{	
	///<summary>
	/// An object representation of the 'Batch' table. [No description found the database]	
	///</summary>
	/// <remarks>
	/// This file is generated once and will never be overwritten.
	/// </remarks>	
	[Serializable, DataObject]
	[CLSCompliant(true)]
	public partial class Batch : BatchBase
	{		
		#region Constructors
		///<summary>
		/// Creates a new <see cref="Batch"/> instance.
		///</summary>
		public Batch():base(){}

		#endregion

    #region Custom fields
    #region GPP
    /// <summary>
    /// Must deep-load
    /// </summary>
    [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
    [DataObjectField(false, false, false)]
    public virtual System.DateTime StartGPP
    {
      get
      {
        DateTime start = this.CreatedAt;
        if (this.DetailBatchGppCollection != null)
        {
          foreach (DetailBatchGpp obj in this.DetailBatchGppCollection)
          {
            if (start > obj.InputTime) start = obj.InputTime;
          }
        }

        return start;
      }

    }

    /// <summary>
    /// Must deep-load
    /// </summary>
    [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
    [DataObjectField(false, false, false)]
    public virtual System.Double StartMeterGPP
    {
      get
      {
        double meter = 0.0;

        if (this.DetailBatchGppCollection != null &&
          this.DetailBatchGppCollection.Count > 0)
        {
          this.DetailBatchGppCollection.Sort("InputTime ASC");
          meter = DetailBatchGppCollection[0].Me1 + DetailBatchGppCollection[0].Me2;
        }

        return meter;
      }

    }

    /// <summary>
    /// Must deep-load
    /// </summary>
    [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
    [DataObjectField(false, false, false)]
    public virtual System.DateTime EndGPP
    {
      get
      {
        DateTime end = this.CreatedAt;
        if (this.DetailBatchGppCollection != null)
        {
          foreach (DetailBatchGpp obj in this.DetailBatchGppCollection)
          {
            if (end < obj.InputTime) end = obj.InputTime;
          }
        }

        return end;
      }

    }
    #endregion

    #region TVT
    /// <summary>
    /// Must deep-load
    /// </summary>
    [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
    [DataObjectField(false, false, false)]
    public virtual System.DateTime StartTVT
    {
      get
      {
        DateTime start = this.CreatedAt;
        if (this.DetailBatchTvtCollection != null)
        {
          foreach (DetailBatchTvt obj in this.DetailBatchTvtCollection)
          {
            if (start > obj.InputTime) start = obj.InputTime;
          }
        }

        return start;
      }

    }

    /// <summary>
    /// Must deep-load
    /// </summary>
    [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
    [DataObjectField(false, false, false)]
    public virtual System.DateTime EndTVT
    {
      get
      {
        DateTime end = this.CreatedAt;
        if (this.DetailBatchTvtCollection != null)
        {
          foreach (DetailBatchTvt obj in this.DetailBatchTvtCollection)
          {
            if (end < obj.InputTime) end = obj.InputTime;
          }
        }

        return end;
      }

    }
    #endregion
    #endregion
  }
}
